package cn.stylefeng.guns.modular.hp.service.imp;

import cn.stylefeng.guns.modular.hp.dao.ExpertDepartmentLinkInfoMapper;
import cn.stylefeng.guns.modular.hp.model.ExpertDepartmentLinkInfo;
import cn.stylefeng.guns.modular.hp.service.IExpertDepartmentLinkInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 专家科室关联关系表 服务实现类
 * </p>
 *
 * @author xzqiang
 * @date 2019-6-10
 */
@Service
public class ExpertDepartmentLinkInfoImpl extends ServiceImpl<ExpertDepartmentLinkInfoMapper, ExpertDepartmentLinkInfo> implements IExpertDepartmentLinkInfoService {

    @Override
    public List<Map<String, Object>> list() {
        return this.baseMapper.list();
    }

    @Override
    public List<ExpertDepartmentLinkInfo> getLinkInfoByExpertInfoId(String expertInfoId) {
        return this.baseMapper.getLinkInfoByExpertInfoId(expertInfoId);
    }

    @Override
    public List<ExpertDepartmentLinkInfo> getLinkInfoByDepartmentInfoId(String departmentInfoId) {
        return this.baseMapper.getLinkInfoByDepartmentInfoId(departmentInfoId);
    }

    @Override
    public ExpertDepartmentLinkInfo getLinkInfoByDepartmentInfoIdAndExpertInfoId(String departmentInfoId, String expertInfoId) {
        return this.baseMapper.getLinkInfoByDepartmentInfoIdAndExpertInfoId(departmentInfoId, expertInfoId);
    }

    @Override
    public int deleteByDepartmentInfoIdAndExpertInfoId(String departmentInfoId, String expertInfoId) {
        return this.baseMapper.deleteByDepartmentInfoIdAndExpertInfoId(departmentInfoId,expertInfoId);
    }

    @Override
    public void setDepartmentLink(String departmentIds, String expertInfoId) {
        String[] dIds = departmentIds.split(",");
        for(String dId : dIds){
            ExpertDepartmentLinkInfo info = this.baseMapper.getLinkInfoByDepartmentInfoIdAndExpertInfoId(dId, expertInfoId);
            if(info == null){
                info = new ExpertDepartmentLinkInfo();
                info.setDepartmentInfoId(dId);
                info.setExpertInfoId(expertInfoId);
                info.setPri(999);
                info.insert();
            }
        }
        //清除不在列表内的数据
        this.baseMapper.delLinkInfoNotInDepartmentIds(expertInfoId, dIds);
    }
}
